package com.example.chatchatbackend.Controller.sendJob;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.chatchatbackend.entity.RestBean;
import com.example.chatchatbackend.entity.dto.send.SendComments;
import com.example.chatchatbackend.entity.vo.request.SendCommentsVO;
import com.example.chatchatbackend.service.sendJob.SendCommentsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 丁真
 * @since 2024-10-28 05:03:47
 */

@Slf4j
@RestController
@RequestMapping("/api/sendComments")
public class SendCommentsController {


    @Autowired
    private SendCommentsService sendCommentsService;

    @GetMapping
    public RestBean<List<SendCommentsVO>> getAllComment(){
        return RestBean.success(sendCommentsService.getAllSendComments());
    }

    @PostMapping
    public RestBean<SendCommentsVO> insertAdv(@RequestBody SendCommentsVO sendCommentsVO){
        SendCommentsVO insertSendCommentsVO = sendCommentsService.insertSendComments(sendCommentsVO);
        return RestBean.success(insertSendCommentsVO);

    }

    @PostMapping("/list")
    public RestBean<List<SendCommentsVO>> insertAdvList (@RequestBody List<SendCommentsVO> sendCommentsVO){
        List<SendCommentsVO> SendCommentsList = sendCommentsService.insertSendCommentsList(sendCommentsVO);
        return RestBean.success(SendCommentsList);
    }

    @GetMapping("/pageThree")
    public RestBean<IPage<SendComments>> pageThree(@RequestParam(value = "pageNum" ,defaultValue = "1") Integer pageNum,
                                                   @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
        return RestBean.success(sendCommentsService.pageThree(pageNum, pageSize));
    }


    @DeleteMapping("/ids")
    public RestBean<String> delete(@RequestBody List<Integer> ids) {
        sendCommentsService.deleteByIds(ids);
        return RestBean.success("删除成功");
    }


}
